/**
 * @author helio
 */
var AccountCheckView = Ext.extend(BasicPanel,{
	inputWin : null,
	
	initlize : function() {
		
		if(!this.detailsGrid) {
						
			this.detailsStore = new Ext.data.Store({
			    proxy: new Ext.ux.data.PagingMemoryProxy(this.detailsJson),
			    //remoteSort:true,
			    reader: new Ext.data.JsonReader({
					root: 'accounts',
					remoteSort: true,
			        fields: ['id','code','name', 'bank', 'classification', 'comment',{name:'amount',type:'float'}]
			    })
			});
			
			// create paging bar
			var pagingBar = new Ext.PagingToolbar({
		        pageSize: 25,
		        store: this.detailsStore,
		        displayInfo: true,
				
				plugins: new Ext.ux.ProgressBarPager()
		    });
			
			var editor = new Ext.ux.grid.RowEditor({
		        saveText: '确认',
				cancelText: '取消',
				listeners : {
					'afteredit' : function(rowEditor, obj, record, rowIndex) {
						SALE.Action.saveBankAccountInfo(function() {
														
							this.showMessage("帐户修改成功！！！");
														
						}.createDelegate(this), record.data, 'modify');
						
					}.createDelegate(this)
				}
		    });
			
			// create the grid
			var csm = new Ext.grid.CheckboxSelectionModel();
			
			this.detailsGrid = new Ext.grid.GridPanel({
				store: this.detailsStore,
				title: '现金银行',
				columns: [csm, {
					header: "开户行",
					dataIndex: 'bank',
					sortable: true,
					width: 70
				}, {
					header: "帐号",
					dataIndex: 'code',
					sortable: true,
					width: 120
				}, {
					header: "帐户名称",
					dataIndex: 'name',
					sortable: true
				}, {
					header: "银行存款科目",
					dataIndex: 'classification',
					sortable: true,
					width: 60,
					editor: new Ext.form.ComboBox({
						tpl: comboxTpl,
				        store: DataStoreUtil.getClassificationsStore(),
				        displayField:'name',
				        typeAhead: true,
				        mode: 'local',
				        forceSelection: false,
				        triggerAction: 'all',
				        emptyText:'输入银行存款科目...',
				        selectOnFocus:true,
						name: 'classification'
					})
				}, {
					header: "帐户余额",
					dataIndex: 'amount',
					sortable: true,
					align: 'right',
					width: 70,
					
					editor: new Ext.form.NumberField({
						allowBlank: true
					})
				}],
				
				sm: csm,
				
				plugins: [editor],
					
				tbar:[{
            		xtype:'splitbutton',
            		text: '入账统计',
            		iconCls: 'icon-menu-money-in',
            		value: '0',
            		handler: this.showLedgerStatistics.createDelegate(this),
           			menu: [{
						text: '按日统计',
						iconCls: 'calendar_view_day',
						value: '0',
						handler: this.showLedgerStatistics.createDelegate(this)
					},{
						text: '按月统计',
						iconCls: 'calendar_view_month',
						value: '1',
						handler: this.showLedgerStatistics.createDelegate(this)
					}]
        		}, '-', {
            		xtype:'splitbutton',
            		text: '出账统计',
            		iconCls: 'icon-menu-money-out',
            		value: '2',
            		handler: this.showLedgerStatistics.createDelegate(this),
           			menu: [{
						text: '按日统计',
						iconCls: 'calendar_view_day',
						value: '2',
						handler: this.showLedgerStatistics.createDelegate(this)
					},{
						text: '按月统计',
						iconCls: 'calendar_view_month',
						value: '3',
						handler: this.showLedgerStatistics.createDelegate(this)
					}]
        		}, '-', {
		            text:'历史记录',
		            tooltip:'账户出账入账历史记录',
		            iconCls:'history',
					handler: TrackRecordMoneyView.showNextOperatePanel.createDelegate(this)
		        }],
				
				bbar: pagingBar,
				
				viewConfig: {
			        forceFit: true,
					enableRowBody:true,
		            showPreview:true
			    },
		
				loadMask: true,
				stripeRows: true,
				border: false,
				autoExpandColumn: 'name',
				layout: 'fit'			
			});
		}
	},
	
	initlizeDataHandler : function(resultJson) {
		this.detailsJson['accounts'] = resultJson.accounts;
		this.detailsStore.load({params:{start:0, limit:25}});
	},
	
	getCorePanel : function() {
		if (!this.detailsGrid) {
			this.initlize();
			SALE.Action.getBankAccountDetailsJson(this.initlizeDataHandler.createDelegate(this));
		}
		return this.detailsGrid;
	},
	
	showLedgerStatistics : function(object) {
		LedgerStatisticsView.showNextOperatePanel(object.value)
	}
});

AccountCheckView.showAccountCheckPanel = function(){
	var  manageView = new AccountCheckView();
	
	SALE.App.showOperateTabPanel(manageView.getCorePanel(), "现金银行");
}